package dataStruct.queue.ex2;

/**
 * Created by thinkpad on 2016/8/24.
 */

import java.util.concurrent.BlockingQueue;
public class Consumer implements Runnable {
    private BlockingQueue<String> queue;
    private String consumer;

    public Consumer(BlockingQueue<String> queue, String consumer) {
        this.queue = queue;
        if (null != consumer)
            this.consumer = consumer;
        else
            this.consumer = "null ";
    }

//    @Override
//    public void run() {
//        try {
//            String uuid = queue.take();
//            System.out.println(consumer + " consum " + uuid
//                    + " " + Thread.currentThread());
//        } catch (InterruptedException e) {
//            System.out.println(e.getMessage());
//        }
//    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 10; i++) {
                String uuid = queue.take();
                System.out.println(consumer + " consum " + uuid
                        + " " + Thread.currentThread());
            }
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
    }
}